package com.kuang.user.service;

import com.kuang.bascic.Myexception.BusinessException;
import com.kuang.bascic.service.BaseServiceImpl;
import com.kuang.bascic.utils.MD5Utils;
import com.kuang.user.domian.LoginInfo;
import com.kuang.user.domian.dto.UserDto;
import com.kuang.user.mapper.LoginInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class LoginServiceImpl extends BaseServiceImpl<LoginInfo> implements LoginService {
    @Autowired
    private LoginInfoMapper loginInfoMapper;
    @Override
    public LoginInfo loadAcount(UserDto userDto) {
        // 做登录判断
        // 通过电话，邮件，用户名去数据库查询账户是否存在
        LoginInfo loginInfo = loginInfoMapper.loadAcount(userDto);
        if (loginInfo!=null){
                // 从数据库查询到了账户信息
            String MD5login = MD5Utils.encrypByMd5(userDto.getPassword() + loginInfo.getSalt());
            if (!MD5login.equals(loginInfo.getPassword())){
                throw new BusinessException("密码错误");
            }
        }else {
            throw new BusinessException("账户不存在");
        }
        return loginInfo;
    }
}
